﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects;
using System.Data.Objects.DataClasses;

namespace ScrumTracker.Model
{
    public partial class ScrumTrackerEntities
    {
        private static ScrumTrackerEntities _instance = null;
        public static ScrumTrackerEntities Instance
        {
            get
            {
                //_instance = _instance ?? new ScrumTrackerEntities();
                return _instance;
            }
        }
        public static void Initialize()
        {
            if (_instance != null)
            {
                _instance.Dispose();
            }
            _instance = new ScrumTrackerEntities();
        }

        public void SafeAttach(object entity)
        {
            ObjectStateEntry entry;
            if (ScrumTrackerEntities.Instance.ObjectStateManager.TryGetObjectStateEntry(entity, out entry))
            {
                if (entry.State == System.Data.EntityState.Detached)
                {
                    ScrumTrackerEntities.Instance.Attach(entity as IEntityWithKey);
                }
            }
        }
    }
}